package com.resys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.resys.entity.enums.PageSize;
import com.resys.entity.query.DeviceQuery;
import com.resys.entity.po.Device;
import com.resys.entity.vo.PaginationResultVO;
import com.resys.entity.query.SimplePage;
import com.resys.mappers.DeviceMapper;
import com.resys.service.DeviceService;
import com.resys.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("deviceService")
public class DeviceServiceImpl implements DeviceService {

	@Resource
	private DeviceMapper<Device, DeviceQuery> deviceMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Device> findListByParam(DeviceQuery param) {
		return this.deviceMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(DeviceQuery param) {
		return this.deviceMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Device> findListByPage(DeviceQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Device> list = this.findListByParam(param);
		PaginationResultVO<Device> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Device bean) {
		return this.deviceMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Device> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.deviceMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Device> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.deviceMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Device bean, DeviceQuery param) {
		StringTools.checkParam(param);
		return this.deviceMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(DeviceQuery param) {
		StringTools.checkParam(param);
		return this.deviceMapper.deleteByParam(param);
	}

	/**
	 * 根据DeviceId获取对象
	 */
	@Override
	public Device getDeviceByDeviceId(Integer deviceId) {
		return this.deviceMapper.selectByDeviceId(deviceId);
	}

	/**
	 * 根据DeviceId修改
	 */
	@Override
	public Integer updateDeviceByDeviceId(Device bean, Integer deviceId) {
		return this.deviceMapper.updateByDeviceId(bean, deviceId);
	}

	/**
	 * 根据DeviceId删除
	 */
	@Override
	public Integer deleteDeviceByDeviceId(Integer deviceId) {
		return this.deviceMapper.deleteByDeviceId(deviceId);
	}

	/**
	 * 根据Name获取对象
	 */
	@Override
	public Device getDeviceByName(String name) {
		return this.deviceMapper.selectByName(name);
	}

	/**
	 * 根据Name修改
	 */
	@Override
	public Integer updateDeviceByName(Device bean, String name) {
		return this.deviceMapper.updateByName(bean, name);
	}

	/**
	 * 根据Name删除
	 */
	@Override
	public Integer deleteDeviceByName(String name) {
		return this.deviceMapper.deleteByName(name);
	}
}